//统一管理咱们项目用户相关的接口
import request from '@/utils/request'
import { AxiosResponse } from 'axios'
import qs from 'qs'
import {
  SchedulePageQuery,
  SchedulePageRes,
  ScheduleParams,
  ScheduleType,
} from './type'

// 项目用户相关的请求地址
enum Schedule_API {
  GET_SCHEDULE_PAGE_BY_ADMIN = '/teaching_system/schedule/more',
  GET_SCHEDULE_PAGE_BY_STU = '/teaching_system/schedule/more/stu/{semesterId}',
  GET_SCHEDULE_PAGE_BY_TEA = '/teaching_system/schedule/more/tea/{semesterId}',
  POST_PUT_SCHEDULE_ONE = '/teaching_system/schedule/one',
  DELETE_SCHEDULE_BY_ID = '/teaching_system/schedule/one/{id}',
}

/**
 * 管理员获取课程安排
 * @param {string} schedulePageQuery 请求安排分页对象
 * @returns
 */
export const reqGetAllScheduleByAdmin = (params: SchedulePageQuery) =>
  request.get<any, AxiosResponse<SchedulePageRes>>(
    Schedule_API.GET_SCHEDULE_PAGE_BY_ADMIN + '?' + qs.stringify(params),
  )

/**
 * 学生获取课程安排
 * @param {string} semesterId
 * @returns
 */
export const reqGetScheduleByStu = (semesterId: number) =>
  request.get<any, AxiosResponse<ScheduleType[]>>(
    Schedule_API.GET_SCHEDULE_PAGE_BY_STU.replace(
      '{semesterId}',
      semesterId.toString(),
    ),
  )

/**
 * 老师获取课程安排
 * @param {string} semesterId
 * @returns
 */
export const reqGetScheduleByTea = (semesterId: number) =>
  request.get<any, AxiosResponse<ScheduleType[]>>(
    Schedule_API.GET_SCHEDULE_PAGE_BY_TEA.replace(
      '{semesterId}',
      semesterId.toString(),
    ),
  )

/**
 * 添加课程安排
 * @param {object} params 新增课程安排表
 * @param {number} params.courseId 课程ID
 * @param {number} params.lessonNumber
 * @param {number} params.classNumber 第几节上课
 * @param {number} params.weekNumber 第几周
 * @param {string} params.dayOfWeek 星期几
 * @param {string} params.classroom 教室
 * @returns
 */
export const reqAddSchedule = (params: ScheduleParams) =>
  request.post<any, AxiosResponse<any>>(
    Schedule_API.POST_PUT_SCHEDULE_ONE,
    params,
  )

/**
 * 更新课程安排
 * @param {object} params 更新课程安排表
 * @param {number} params.scheduleId 安排ID
 * @param {number} params.courseId 课程ID
 * @param {number} params.lessonNumber
 * @param {number} params.classNumber 第几节上课
 * @param {number} params.weekNumber 第几周
 * @param {string} params.dayOfWeek 星期几
 * @param {string} params.classroom 教室
 * @returns
 */
export const reqUpdateSchedule = (params: ScheduleParams) =>
  request.put<any, AxiosResponse<any>>(
    Schedule_API.POST_PUT_SCHEDULE_ONE,
    params,
  )

/**
 * 删除课程安排
 * @param {string} id
 * @returns
 */
export const reqDeleteScheduleById = (id: number) =>
  request.delete<any, AxiosResponse<any>>(
    Schedule_API.DELETE_SCHEDULE_BY_ID.replace('{id}', id.toString()),
  )
